package com.frogs.ucenter.v1.request;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import com.frogs.framework.util.date.DateUtil;
import com.frogs.framework.web.HttpRequestInfo;
import com.frogs.system.util.ApiUrlParamEnum;
import com.frogs.system.web.api.request.Request;
import com.frogs.system.web.exception.RequestIllegalException;

public class RechargeListByDateRequest extends Request {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6484232799742285637L;

	//开始日期
	private Date startDate =null;
	
	//结束日期
	private Date endDate =null;
	//页数
	private int pageNo; 
	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	//每页条数
	private int pageSize;
	
	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	@Override
	public void parse(HttpServletRequest request) {
		HttpRequestInfo requestInfo = new HttpRequestInfo(request);
		
		this.startDate = requestInfo.getDateParameter(ApiUrlParamEnum.startDate.getParamName(), "yyyy-MM-dd");
		this.endDate = requestInfo.getDateParameter(ApiUrlParamEnum.endDate.getParamName(), "yyyy-MM-dd");
		this.pageNo = requestInfo.getIntParameter(ApiUrlParamEnum.pageNo.getParamName(), 1);
		this.pageSize = requestInfo.getIntParameter(ApiUrlParamEnum.pageSize.getParamName(), 20);
		int num = DateUtil.getIntervalDays(startDate, endDate);
		if ( num <1 ) {
			throw new RequestIllegalException("error date: 开始日期必须小于结束日期");
		}else if(num>3){
			throw new RequestIllegalException("error date: 开始日期与结束日期的时间差必须小于等于3天");
		}
	}
	
}
